﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BK.Model.ViewModels.PaymentEditViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<script type="text/javascript">
		$().ready(function ()
		{
			$("#paymentFields input[type='text']").width("25em");
			$("#paymentFields select").width("25em");

			$("#Payment_UserId").change(function ()
			{
				$.ajax(
				{
					url: '<%= Page.ResolveUrl("~/HttpHandlers/CategoriesHandler.ashx") %>',
					data:
					{
						userId: getSelectedUserId()
					},
					success: function (data)
					{
						var paymentCategoryDropDown = $("#Payment_CategoryId");
						paymentCategoryDropDown.empty().data("option");
						for (var i = 0; i < data.length; i++)
						{
							paymentCategoryDropDown.append($("<option/>").
								attr("value", data[i].Id).text(data[i].Text));
						}
					}
				});
				updateUI();
			});

			updateUI();
		})

		function fillSelect(dtoList)
		{
			alert("Not implemented yet");
		}

		function updateUI()
		{
			return;
			$("#paymentFields .editor-field-container").not("#userSelection").each(function ()
			{
				setEnabled(this, getSelectedUserId());
			});
			$("#btnSubmit").each(function ()
			{
				setEnabled(this, getSelectedUserId());
			});
		}

		function getSelectedUserId()
		{
			return $("#Payment_UserId :selected").val();
		}
	</script>
	<h2>
		Платежі
	</h2>
	<% Html.EnableClientValidation(); %>
	<% using (Html.BeginForm())
	{%>
	<%: Html.ValidationSummary(true) %>
	<fieldset id="paymentFields">
		<legend>
			<% Response.Write(Model.Payment.Id == 0 ? "Створення новго запису" : "Редагування"); %></legend>
		<table>
			<tr>
				<td>
					<div class="editor-field">
						<%: Html.HiddenFor(model => model.Payment.Id)%>
						<%= Html.HiddenFor(model =>  model.Payment.UserId) %>
					</div>
					<div id="categorySelection" class="editor-field-container">
						<%--<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.CategoryId)%>
						</div>--%>
						<%--<div class="editor-field">
							<%=Html.DropDownList("Payment.CategoryId",
												from category in Model.Categories
												select new SelectListItem
														{
															Text = category.FullName,
															Value = category.Id.ToString(),
															Selected = category.Id == Model.Payment.CategoryId
														}, "-")%>
							<%: Html.ValidationMessageFor(model => model.Payment.CategoryId)%>
						</div>--%>
					</div>
					<div id="amount" class="editor-field-container">
						<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.Amount)%>
						</div>
						<div class="editor-field">
							<%: Html.TextBoxFor(model => model.Payment.Amount, String.Format("{0:F}", Model.Payment.Amount))%>
							<%: Html.ValidationMessageFor(model => model.Payment.Amount)%>
						</div>
					</div>
					<%--<div id="accountSelection" class="editor-field-container">
						<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.AccountId)%>
						</div>
						<div class="editor-field">
							<%=Html.DropDownList("Payment.AccountId",
												from account in Model.Accounts
												select new SelectListItem
														{
															Text = account.Name,
															Value = account.Id.ToString(),
															Selected = account.Id == Model.Payment.AccountId
														}, "-")%>
							<%: Html.ValidationMessageFor(model => model.Payment.AccountId)%>
						</div>
					</div>--%>
					<div id="description" class="editor-field-container">
						<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.Description)%>
						</div>
						<div class="editor-field">
							<%: Html.TextBoxFor(model => model.Payment.Description)%>
							<%: Html.ValidationMessageFor(model => model.Payment.Description)%>
						</div>
					</div>
					<div id="dateTime" class="editor-field-container">
						<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.DateTime)%>
						</div>
						<div class="editor-field">
							<%: Html.TextBoxFor(model => model.Payment.DateTime, String.Format("{0:g}", Model.Payment.DateTime))%>
							<%: Html.ValidationMessageFor(model => model.Payment.DateTime)%>
						</div>
					</div>
					<%--<div id="targetSelection" class="editor-field-container">
						<div class="editor-label">
							<%: Html.LabelFor(model => model.Payment.TargetId)%>
						</div>
						<div class="editor-field">
							<%=Html.DropDownList("Payment.TargetId",
												from category in Model.Targets
												select new SelectListItem
														{
															Text = category.FullName,
															Value = category.Id.ToString(),
															Selected = category.Id == Model.Payment.CategoryId
														}, "-")%>
							<%: Html.ValidationMessageFor(model => model.Payment.TargetId)%>
						</div>
					</div>--%>
				</td>
			</tr>
			<tr>
				<td>
					<input id="btnSubmit" type="submit" value="Зберегти" />
				</td>
			</tr>
		</table>
	</fieldset>
	<% } %>
	<div>
		<%: Html.ActionLink("Повернутися до списку", "Index") %>
	</div>
</asp:Content>
